<template>
	<view>
		<view class="header">
			<view class="header-b">
				<view><image src="../../static/stock/left.png" mode=""></image></view>
				<view class="">货品搜索</view>
				<view class="more" @click.self="obscuration">
					<view class="more-more" v-if="showMore" @click="obscuration">
						<view class="showmore-one">
							<image src="../../static/stock/05.png" mode=""></image>
							库存统计
						</view>
						<view class="showmore-one">
							<image src="../../static/stock/06.png" mode=""></image>
							库存变动
						</view>
						<view class="showmore-one ">
							<image src="../../static/stock/07.png" mode=""></image>
							库存预警
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="seach">
			<view class="seach-s">
				<image src="../../static/images/tb_search.png" mode=""></image>
				<input type="text" value="" placeholder="请输入关键词..." v-model="seach" @blue="add" placeholder-class="f28 c999" />
			</view>
		</view>
		<view class="classify">
			<view class="classify-l" @click="showdow">
				{{ msg }}
				<image src="../../static/images/arrow_down.png" mode=""></image>
			</view>
			<view class="classify-l" @click="showO">
				{{ mst }}
				<image src="../../static/slice/1.png" mode=""></image>
			</view>
			<view class="classify-l" @click="showTT">
				{{ msy }}
				<image src="../../static/slice/1.png" mode=""></image>
			</view>
		</view>
		<!-- 下拉 -->
		<view v-show="show" class="combobox">
			<view class="show-li" @click="showtrue(-1)">全部分类</view>
			<view class="show-li" @click="showtrue(index, item)" v-for="(item, index) in leiNmae" :key="item.category_id">{{ item.name }}</view>
		</view>

		<!-- 下拉 -->
		<view v-show="showone" class="combobox">
			<view class="show-li" @click="showOO(0)">全部</view>
			<view class="show-li" @click="showOO(1)">上架</view>
			<view class="show-li" @click="showOO(2)">下架</view>
		</view>
		<!-- 下拉 -->
		<view v-show="showtwo" class="combobox">
			<view class="show-li" @click="showt(0)">智能排序</view>
			<view class="show-li" @click="showt(1)">上架时间(最近)</view>
			<view class="show-li" @click="showt(2)">上架时间(最早)</view>
			<view class="show-li" @click="showt(3)">更新时间(最近)</view>
			<view class="show-li" @click="showt(4)">更新时间(最早)</view>
			<!-- 	<view class="show-li" @click="showt(5)">销售从高到低</view>
			<view class="show-li" @click="showt(6)">销售从低到高</view>
			<view class="show-li" @click="showt(7)">库存从高到低</view>
			<view class="show-li" @click="showt(8)">库存从低到高</view> -->
		</view>
		<view class="ima" v-if="shop"><image src="../../static/slice/86438f8f6d0029f503d57efb448590f.png" mode="aspectFit"></image></view>
		<view class="" v-if="shopMall" v-for="(item, index) in arry" :key="index" @click="goall(item,item.goods_id)">
			<view class="supershop">
				<view class="pic">
					<dimg :src="item.cover"></dimg>
				</view>
				<view class="supershop-sp">
					<view class="supershop-spa">{{ item.title }}</view>
					<view class="supershop-spa">
						库存: 100
					</view>
				</view>
				<view class="supershop-top">
					<view class="blue" style="margin-top: 50rpx; color: red;">￥{{ item.max_price }}</view>
				</view>
			</view>
			<!-- 展开按钮功能 -->
		</view>

		<!-- 蒙层 -->
		<view class="black" v-show="track"></view>
	</view>
</template>

<script>
import uniIcons from '@/components/uni-icons/uni-icons.vue';
export default {
	components: {
		uniIcons
	},
	onLoad() {
		this.fenlei();
		this.showshop();
	},
	onShow() {
	this.state=uni.getStorageSync('state')
		// console.log(this.state);
	},
	data() {
		return {
			shopMall: true,
			arry: [],
			addy: [],
			msy: '智能排序',
			mst: '全部',
			showone: false,
			show: false,
			showtru: true,
			shop: false,
			showZhan: '展开',
			image: '../../static/images/arrow_down.png',
			unfolt: false, //展开按钮,
			showPut: false,
			track: false,
			showMore: false,
			msg: '全部分类',
			// 分类名字
			leiNmae: {},
			showtwo: false,
			allKucn: '',
			seach: '',
			any: [],
			pandian:[]
		};
	},
	methods: {
		showdow() {
			if (this.show) {
				this.show = false;
				this.showone = false;
				this.showtwo = false;
			} else {
				this.show = true;
				this.showone = false;
				this.showtwo = false;
			}
		},

		showtrue(index, item) {
			if (index == -1) {
				this.arry = this.addy;
				this.msg = '全部分类';
				this.show = false;
				return;
			}
			this.arry = this.addy;
			this.show = false;
			this.msg = item.name;
			this.arry = this.arry.filter(item => {
				return item.category_name == this.msg;
			});
		},
		// showZhankai(item, index) {
		// 	if (item.show == true) {
		// 		this.image = '../../static/images/arrow_down.png';
		// 	} else {
		// 		this.image = '../../static/images/arrow_ondown.png';
		// 	}
		// 	this.arry[index].show = !this.arry[index].show;
		// 	this.$set(this.arry, index, this.arry[index]);
		// },
		shhowdian(index) {
			this.arry[index].showdian = !this.arry[index].showdian;
			this.$set(this.arry, index, this.arry[index]);
		},
		// 开启蒙层
		obscuration() {
			this.track = !this.track;
			this.showMore = !this.showMore;
		},
		// 关闭蒙层
		closeMore() {
			this.track = false;
			this.showMore = false;
			console.log(this.showMore);
		},
		// 库存查询
		showIndex() {},
		// 商品分类
		fenlei() {
			this.$ajax('api/v1.goods/categoryList', {}, 'GET').then(res => {
				// console.log(res);
				this.leiNmae = res.result;
			});
		},
		//上架
		showO() {
			this.showone = !this.showone;
			this.show = false;
			this.showtwo = false;
		},
		showOO(e) {
			if (e == 0) {
				this.mst = '全部';
				this.arry = this.addy;
				console.log(this.arry);
			}
			if (e == 1) {
				this.mst = '上架';
				this.arry = this.addy;
				this.arry = this.arry.filter(item => {
					return item.status == 1;
				});
			}
			if (e == 2) {
				this.mst = '下架';
				this.arry = this.addy;
				this.arry = this.arry.filter(item => {
					return item.status == 0;
				});
			}
			this.showone = false;
		},
		showTT() {
			this.showone = false;
			this.show = false;
			this.showtwo = !this.showtwo;
		},
		showt(e) {
			this.showtwo = false;
			if (e == 0) {
				this.addy = this.arry;
				this.msy = '智能排序';
			}
			if (e == 1) {
				this.addy = this.arry;
				this.msy = '上架时间(最近)';
				function compare(property) {
					return function(a, b) {
						var value1 = a[property];
						var value2 = b[property];
						return value2 - value1; // value1-value2是从小到大    如果是从大到小 return value2 -value1
					};
				}
				this.arry.sort(compare('create_time'));
			}
			if (e == 2) {
				this.addy = this.arry;
				this.msy = '上架时间(最早)';
				console.log(this.arry);
				function compare(property) {
					return function(a, b) {
						var value1 = a[property];
						var value2 = b[property];
						return value1 - value2; // value1-value2是从小到大    如果是从大到小 return value2 -value1
					};
				}
				this.arry.sort(compare('create_time'));
			}
			if (e == 3) {
				console.log(this.arry);
				this.msy = '更新时间(最近)';
				this.addy = this.arry;
				this.msy = '上架时间(最早)';
				console.log(this.arry);
				function compare(property) {
					return function(a, b) {
						var value1 = a[property];
						var value2 = b[property];
						return value1 - value2; // value1-value2是从小到大    如果是从大到小 return value2 -value1
					};
				}
				this.arry.sort(compare('update_time'));
			}
			if (e == 4) {
				this.msy = '更新时间(最早)';
				console.log(this.arry);
				this.msy = '更新时间(最近)';
				this.addy = this.arry;
				this.msy = '上架时间(最早)';
				console.log(this.arry);
				function compare(property) {
					return function(a, b) {
						var value1 = a[property];
						var value2 = b[property];
						return value2 - value1; // value1-value2是从小到大    如果是从大到小 return value2 -value1
					};
				}
				this.arry.sort(compare('update_time'));
			}
			// if (e == 5) {
			// 	this.msy = '销售从高到低';
			// 	console.log(this.arry);
			// }
			// if (e == 6) {
			// 	this.msy = '销售从低到高';
			// 	this.type = e;
			// 	function compare(property) {
			// 		return function(a, b) {
			// 			var value1 = a[property];
			// 			var value2 = b[property];
			// 			return value1 - value2;
			// 		};
			// 		this.arry = this.arry.sort(compare(''));
			// 	}
			// }
			// if (e == 7) {
			// 	// console.log(this.arry);

			// 	this.msy = '库存从高到低';

			// }
			// if (e == 8) {
			// 	this.msy = '库存从低到高';
			// }
		},
		showshop() {
			this.$ajax('api/v2.goods/index', {})
				.then(res => {
					this.arry = res.result;
					this.addy = res.result;
					if (this.arry.length == 0) {
						this.shop = true;
						this.shopMall = false;
					}
					// console.log(this.arry);
					this.arry.forEach(item => {
						item.show = false;
						item.showdian = false;
					});
				
				})
				.catch(res => {
					console.log(Error);
				});
		},
		kucun(e) {
			let b = 0;
			e.product_list.forEach(item => {
				b = item.store_num + b;
			});
			return b;
		},
		qian(e) {
			let b = 0;
			e.product_list.forEach(item => {
				b = item.owe_num + b;
			});
			return b;
		},
		gosuply(e) {
			uni.navigateTo({
				url: 'storage?item=' + JSON.stringify(e)
			});
		},
		add() {
			console.log(123);
		},
		goall(e,id) {
		
			uni.setStorage({
				key:'pandian',
				data:e
			})
			uni.navigateTo({
				url:'../shop/proceedInventory'
			})
			
			
		}
	},
	watch: {
		seach(newValue, oldValue) {
			this.arry = this.addy;
			this.seach = newValue;
			this.arry = this.arry.filter(item => {
				return item.title.indexOf(this.seach) != -1;
			});
		}
	}
};
</script>

<style lang="scss">
page {
	background-color: #f5f5f5;
}
.header {
	width: 750rpx;
	background:#249AF6;
	.header-b {
		display: flex;
		font-size: 36rpx;
		font-family: PingFang SC;
		font-weight: 500;
		justify-content: space-between;
		color: #ffffff;
		padding: 60rpx 30rpx 24rpx 30rpx;
		image {
			width: 21rpx;
			height: 38rpx;
		}
		.more {
			font-size: 32rpx;
			font-family: PingFang SC;
			font-weight: 500;
			position: relative;
			.more-more {
				width: 255rpx;
				height: 334rpx;
				background-color: #ffffff;
				font-size: 30rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #333333;
				z-index: 999;
				position: absolute;
				left: -255rpx;

				.showmore-one {
					height: 112rpx;
					line-height: 100rpx;
					border-bottom: 2rpx solid #cccccc;
					&:nth-child(3) {
						border-bottom: none;
					}

					image {
						width: 40rpx;
						height: 40rpx;
						// margin-top: 35rpx;
						margin-right: 34rpx;
						margin-left: 34rpx;
						vertical-align: middle;
					}
				}
			}
		}
	}

	.header-s {
		width: 143rpx;
		height: 34rpx;
		font-size: 36rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: rgba(255, 255, 255, 1);
		line-height: 48rpx;
	}
}
.seach {
	width: 750rpx;
	background-color: #249AF6;
	padding-left: 32rpx;
	display: flex;
	padding-bottom: 25rpx;

	.seach-s {
		width: 700rpx;
		height: 60rpx;
		background: rgba(255, 255, 255, 1);
		border-radius: 99999rpx;
		padding-left: 27rpx;
		display: flex;
		box-sizing: border-box;
		input {
			padding-top: 10rpx;
			border-style: none;
			font-size: 28rpx;
			color: #999;
		}
		image {
			width: 31rpx;
			height: 28rpx;
			margin-top: 15rpx;
			margin-right: 20rpx;
		}
	}
	.seach-e {
		image {
			width: 44rpx;
			height: 44rpx;
			margin-top: 12rpx;
			margin-left: 10rpx;
		}
	}
}
.classify {
	display: flex;
	justify-content: space-around;
	font-size: 32rpx;
	font-family: PingFang SC;
	font-weight: 500;
	color: rgba(51, 51, 51, 1);
	height: 90rpx;
	line-height: 90rpx;
	background-color: #ffffff;
	border-bottom: 21rpx solid #f5f5f5;
	image {
		width: 17rpx;
		height: 10rpx;
		margin-left: 11rpx;
	}
}
.ima {
	display: flex;
	justify-content: center;
	align-items: center;
	margin-top: 227rpx;
	image {
		width: 370upx;
		height: 390upx;
	}
}

.combobox {
	width: 100%;
	background-color: #ffffff;
	position: fixed;
	font-size: 30rpx;
	font-family: PingFang SC;
	font-weight: 500;
	color: #333333;
	line-height: 48rpx;
	padding-left: 30rpx;
	z-index: 2;
	.show-li {
		height: 90rpx;
		line-height: 90rpx;
		border-bottom: 2rpx solid #eeeeee;
		image {
			width: 38rpx;
			height: 32rpx;
			margin: 50rpx;
			float: right;
		}
	}
}
.show {
	display: none;
}
.show-li:hover {
	color: #249af6;
}
.showtrue {
	display: none;
}
.supershop {
	height: 210rpx;
	background-color: #ffffff;
	padding: 40rpx 31rpx;
	line-height: 210rpx;
	box-sizing: border-box;
	display: flex;
	position: relative;
	border-bottom: 2rpx solid #eee;
	&:last-child{
		border-bottom: none;
	}
   .pic{
	   margin-right: 30rpx;
	   width: 130rpx;
	   height: 130rpx;
	   image {
	   	width: 100%;
	   	height: 100%x;
	   }
   }


	.supershop-sp {
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: rgba(51, 51, 51, 1);
		line-height: 60rpx;
	}
	.supershop-top {
		line-height: 60rpx;
		font-size: 28rpx;
		font-family: PingFang SC;
		font-weight: 500;
		position: absolute;
		right: 50rpx;
		.put {
			width: 345rpx;
			height: 161rpx;
			position: absolute;
			left: -345rpx;
			background-color: blue;
			z-index: 2;
			padding-top: 34rpx;
			box-sizing: border-box;
			background-color: #ffffff;
			box-shadow: 3rpx 6upx 8upx rgba(124, 124, 124, 0.2);
			.put-top {
				display: flex;
				justify-content: space-evenly;
				image {
					width: 44rpx;
					height: 44rpx;
				}
			}
		}
		image {
			width: 49rpx;
			height: 10rpx;
			position: relative;
			top: -10rpx;
		}
		.blue {
			image {
				margin-left: 10rpx;
				width: 17rpx;
				height: 10rpx;
			}
		}
	}
}
.unfolt {
	height: 200rpx;
	background-color: #eeeeee;
	font-size: 32rpx;
	font-family: PingFang SC;
	font-weight: 500;
	color: rgba(51, 51, 51, 1);
	.unfolt-t {
		display: flex;
		justify-content: space-around;
		height: 100rpx;
		line-height: 100rpx;
		border-bottom: 2rpx solid #cccccc;
		.unfolt-one {
			position: relative;
			left: 64rpx;
		}
		.unfolt-two {
			position: relative;
			left: 64rpx;
		}
		.unfolt-three {
			position: relative;
			left: 50rpx;
		}
	}
	.unfolt-b {
		display: flex;
		justify-content: space-around;
		height: 100rpx;
		line-height: 100rpx;
		border-bottom: 2rpx solid #cccccc;
		.unfolt-one {
			position: relative;
			left: 48rpx;
		}
		.unfolt-two {
			position: relative;
			left: 30rpx;
		}
		.unfolt-three {
			position: relative;
			left: 30rpx;
		}
	}
}
.stock-b {
	width: 100%;
	position: fixed;
	bottom: 0;
}
.stock-btn {
	display: flex;
	justify-content: space-around;
}
.red {
	color: red;
}
.blue {
	color: #249af6;
}
.black {
	width: 100%;
	position: fixed;
	top: 0;
	height: 100%;
	background-color: #333333;
	opacity: 0.5;
	z-index: 2;
}
</style>
